<!DOCTYPE html>
<html lang="en">
  <head>
    <title>NextLevel  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a title="NextLevel  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">NextLevel Docs</a> (62% documented)</p>
        <p class="header-right"><a href="https://github.com/NextLevel/NextLevel"><img src="img/gh.png"/>View on GitHub</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">NextLevel Reference</a>
        <img id="carat" src="img/carat.png" />
        NextLevel  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/NextLevel.html">NextLevel</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelARConfiguration.html">NextLevelARConfiguration</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelAudioConfiguration.html">NextLevelAudioConfiguration</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelBufferRenderer.html">NextLevelBufferRenderer</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelClip.html">NextLevelClip</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelConfiguration.html">NextLevelConfiguration</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelConfiguration/AspectRatio.html">– AspectRatio</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelGIFCreator.html">NextLevelGIFCreator</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelPhotoConfiguration.html">NextLevelPhotoConfiguration</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelSession.html">NextLevelSession</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NextLevelVideoConfiguration.html">NextLevelVideoConfiguration</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Global Variables.html">Global Variables</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB15ClipFilenameKeySSvp">NextLevelClipFilenameKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB15ClipInfoDictKeySSvp">NextLevelClipInfoDictKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB11ErrorDomainSSvp">NextLevelErrorDomain</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB19PhotoCroppedJPEGKeySSvp">NextLevelPhotoCroppedJPEGKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB12PhotoJPEGKeySSvp">NextLevelPhotoJPEGKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB16PhotoMetadataKeySSvp">NextLevelPhotoMetadataKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB16PhotoRawImageKeySSvp">NextLevelPhotoRawImageKey</a>
              </li>
              <li class="nav-group-task">
                <a href="Global Variables.html#/s:9NextLevel0aB17PhotoThumbnailKeySSvp">NextLevelPhotoThumbnailKey</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Enums/NextLevelAuthorizationStatus.html">NextLevelAuthorizationStatus</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/NextLevelCaptureMode.html">NextLevelCaptureMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/NextLevelDeviceType.html">NextLevelDeviceType</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/NextLevelError.html">NextLevelError</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/NextLevelMirroringMode.html">NextLevelMirroringMode</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureConnection.html">AVCaptureConnection</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureDevice.html">AVCaptureDevice</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureDevice/Format.html">– Format</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureDevice/Position.html">– Position</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureDevice/WhiteBalanceGains.html">– WhiteBalanceGains</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureDeviceInput.html">AVCaptureDeviceInput</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/AVCaptureVideoOrientation.html">AVCaptureVideoOrientation</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/CIContext.html">CIContext</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/CMSampleBuffer.html">CMSampleBuffer</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Comparable.html">Comparable</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Data.html">Data</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Date.html">Date</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/FileManager.html">FileManager</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/UIImage.html">UIImage</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/NextLevelDelegate.html">NextLevelDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols.html#/NextLevelDepthDataDelegate">NextLevelDepthDataDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelDeviceDelegate.html">NextLevelDeviceDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelFlashAndTorchDelegate.html">NextLevelFlashAndTorchDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelMetadataOutputObjectsDelegate.html">NextLevelMetadataOutputObjectsDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelPhotoDelegate.html">NextLevelPhotoDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelPortraitEffectsMatteDelegate.html">NextLevelPortraitEffectsMatteDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelPreviewDelegate.html">NextLevelPreviewDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NextLevelVideoDelegate.html">NextLevelVideoDelegate</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB17DeviceOrientationa">NextLevelDeviceOrientation</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB14DevicePositiona">NextLevelDevicePosition</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB12ExposureModea">NextLevelExposureMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB9FlashModea">NextLevelFlashMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB9FocusModea">NextLevelFocusMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB9TorchModea">NextLevelTorchMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB22VideoStabilizationModea">NextLevelVideoStabilizationMode</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9NextLevel0aB16WhiteBalanceModea">NextLevelWhiteBalanceMode</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <p><img src="https://raw.github.com/NextLevel/NextLevel/master/NextLevel%402x.png" alt="Next Level" style="max-width:100%;"></p>

<p><code><a href="Classes/NextLevel.html">NextLevel</a></code> is a <a href="https://developer.apple.com/swift/">Swift</a> camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage <code>AVFoundation</code> or <code>ARKit</code>.</p>

<p><a href="https://travis-ci.org/NextLevel/NextLevel"><img src="https://travis-ci.org/NextLevel/NextLevel.svg?branch=master" alt="Build Status"></a> <a href="http://cocoadocs.org/docsets/NextLevel/"><img src="https://img.shields.io/cocoapods/v/NextLevel.svg?style=flat" alt="Pod Version"></a> <a href="https://developer.apple.com/swift"><img src="https://img.shields.io/badge/language-swift%205.0-brightgreen.svg" alt="Swift Version"></a> <a href="https://github.com/NextLevel/NextLevel/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-lightgrey.svg" alt="GitHub license"></a></p>

<table><thead>
<tr>
<th style="text-align: center"></th>
<th style="text-align: left">Features</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: center">&#127916;</td>
<td style="text-align: left">“<a href="http://vine.co">Vine</a>-like” video clip recording and editing</td>
</tr>
<tr>
<td style="text-align: center">&#128444;</td>
<td style="text-align: left">photo capture (raw, jpeg, and video frame)</td>
</tr>
<tr>
<td style="text-align: center">&#128070;</td>
<td style="text-align: left">customizable gestural interaction and interface</td>
</tr>
<tr>
<td style="text-align: center">&#128160;</td>
<td style="text-align: left"><a href="https://developer.apple.com/arkit/">ARKit integration</a> (beta)</td>
</tr>
<tr>
<td style="text-align: center">&#128247;</td>
<td style="text-align: left">dual, wide angle, telephoto, &amp; true depth support</td>
</tr>
<tr>
<td style="text-align: center">&#128034;</td>
<td style="text-align: left">adjustable frame rate on supported hardware (ie fast/slow motion capture)</td>
</tr>
<tr>
<td style="text-align: center">&#127906;</td>
<td style="text-align: left">depth data capture support &amp; portrait effects matte support</td>
</tr>
<tr>
<td style="text-align: center">&#128269;</td>
<td style="text-align: left">video zoom</td>
</tr>
<tr>
<td style="text-align: center">&#9878;</td>
<td style="text-align: left">white balance, focus, and exposure adjustment</td>
</tr>
<tr>
<td style="text-align: center">&#128294;</td>
<td style="text-align: left">flash and torch support</td>
</tr>
<tr>
<td style="text-align: center">&#128111;</td>
<td style="text-align: left">mirroring support</td>
</tr>
<tr>
<td style="text-align: center">&#9728;</td>
<td style="text-align: left">low light boost</td>
</tr>
<tr>
<td style="text-align: center">&#128374;</td>
<td style="text-align: left">smooth auto-focus</td>
</tr>
<tr>
<td style="text-align: center">&#9881;</td>
<td style="text-align: left">configurable encoding and compression settings</td>
</tr>
<tr>
<td style="text-align: center">&#128736;</td>
<td style="text-align: left">simple media capture and editing API</td>
</tr>
<tr>
<td style="text-align: center">&#127744;</td>
<td style="text-align: left">extensible API for image processing and CV</td>
</tr>
<tr>
<td style="text-align: center">&#128008;</td>
<td style="text-align: left">animated GIF creator</td>
</tr>
<tr>
<td style="text-align: center">&#128526;</td>
<td style="text-align: left">face recognition; qr- and bar-codes recognition</td>
</tr>
<tr>
<td style="text-align: center">&#128038;</td>
<td style="text-align: left"><a href="https://developer.apple.com/swift/">Swift 5</a></td>
</tr>
</tbody></table>

<p>Need a different version of Swift?</p>

<ul>
<li><code>5.0</code> - Target your Podfile to the latest release or master</li>
<li><code>4.2</code> - Target your Podfile to the <code>swift4.2</code> branch</li>
</ul>
<h2 id='quick-start' class='heading'>Quick Start</h2>
<pre class="highlight ruby"><code>
<span class="c1"># CocoaPods</span>
<span class="n">pod</span> <span class="s2">"NextLevel"</span><span class="p">,</span> <span class="s2">"~&gt; 0.16.0"</span>

<span class="c1"># Carthage</span>
<span class="n">github</span> <span class="s2">"nextlevel/NextLevel"</span> <span class="o">~&gt;</span> <span class="mf">0.16</span><span class="o">.</span><span class="mi">0</span>

<span class="c1"># Swift PM</span>
<span class="n">let</span> <span class="n">package</span> <span class="o">=</span> <span class="no">Package</span><span class="p">(</span>
    <span class="ss">dependencies: </span><span class="p">[</span>
        <span class="o">.</span><span class="no">Package</span><span class="p">(</span><span class="ss">url: </span><span class="s2">"https://github.com/nextlevel/NextLevel"</span><span class="p">,</span> <span class="ss">majorVersion: </span><span class="mi">0</span><span class="p">)</span>
    <span class="p">]</span>
<span class="p">)</span>

</code></pre>

<p>Alternatively, drop the NextLevel <a href="https://github.com/NextLevel/NextLevel/tree/master/Sources">source files</a> or project file into your Xcode project.</p>
<h2 id='important-configuration-note-for-arkit-and-true-depth' class='heading'>Important Configuration Note for ARKit and True Depth</h2>

<p>ARKit and the True Depth Camera software features are enabled with the inclusion of the Swift compiler flag <code>USE_ARKIT</code> and <code>USE_TRUE_DEPTH</code> respectively.</p>

<p>Apple will <a href="https://github.com/NextLevel/NextLevel/issues/106">reject</a> apps that link against ARKit or the True Depth Camera API and do not use them.</p>

<p>If you use Cocoapods, you can include <code>-D USE_ARKIT</code> or <code>-D USE_TRUE_DEPTH</code> with the following <code>Podfile</code> addition or by adding it to your Xcode build settings.</p>
<pre class="highlight ruby"><code>  <span class="n">installer</span><span class="p">.</span><span class="nf">pods_project</span><span class="p">.</span><span class="nf">targets</span><span class="p">.</span><span class="nf">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">target</span><span class="o">|</span>
    <span class="c1"># setup NextLevel for ARKit use</span>
    <span class="k">if</span> <span class="n">target</span><span class="p">.</span><span class="nf">name</span> <span class="o">==</span> <span class="s1">'NextLevel'</span>
      <span class="n">target</span><span class="p">.</span><span class="nf">build_configurations</span><span class="p">.</span><span class="nf">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
        <span class="n">config</span><span class="p">.</span><span class="nf">build_settings</span><span class="p">[</span><span class="s1">'OTHER_SWIFT_FLAGS'</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'$(inherited)'</span><span class="p">,</span> <span class="s1">'-DUSE_ARKIT'</span><span class="p">]</span>
      <span class="k">end</span>
    <span class="k">end</span>
  <span class="k">end</span>
</code></pre>
<h2 id='overview' class='heading'>Overview</h2>

<p>Before starting, ensure that permission keys have been added to your app&rsquo;s <code>Info.plist</code>.</p>
<pre class="highlight xml"><code><span class="nt">&lt;key&gt;</span>NSCameraUsageDescription<span class="nt">&lt;/key&gt;</span>
    <span class="nt">&lt;string&gt;</span>Allowing access to the camera lets you take photos and videos.<span class="nt">&lt;/string&gt;</span>
<span class="nt">&lt;key&gt;</span>NSMicrophoneUsageDescription<span class="nt">&lt;/key&gt;</span>
    <span class="nt">&lt;string&gt;</span>Allowing access to the microphone lets you record audio.<span class="nt">&lt;/string&gt;</span>
</code></pre>
<h3 id='recording-video-clips' class='heading'>Recording Video Clips</h3>

<p>Import the library.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">NextLevel</span>
</code></pre>

<p>Setup the camera preview.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">screenBounds</span> <span class="o">=</span> <span class="kt">UIScreen</span><span class="o">.</span><span class="n">main</span><span class="o">.</span><span class="n">bounds</span>
<span class="k">self</span><span class="o">.</span><span class="n">previewView</span> <span class="o">=</span> <span class="kt">UIView</span><span class="p">(</span><span class="nv">frame</span><span class="p">:</span> <span class="n">screenBounds</span><span class="p">)</span>
<span class="k">if</span> <span class="k">let</span> <span class="nv">previewView</span> <span class="o">=</span> <span class="k">self</span><span class="o">.</span><span class="n">previewView</span> <span class="p">{</span>
    <span class="n">previewView</span><span class="o">.</span><span class="n">autoresizingMask</span> <span class="o">=</span> <span class="p">[</span><span class="o">.</span><span class="n">flexibleWidth</span><span class="p">,</span> <span class="o">.</span><span class="n">flexibleHeight</span><span class="p">]</span>
    <span class="n">previewView</span><span class="o">.</span><span class="n">backgroundColor</span> <span class="o">=</span> <span class="kt">UIColor</span><span class="o">.</span><span class="n">black</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">previewLayer</span><span class="o">.</span><span class="n">frame</span> <span class="o">=</span> <span class="n">previewView</span><span class="o">.</span><span class="n">bounds</span>
    <span class="n">previewView</span><span class="o">.</span><span class="n">layer</span><span class="o">.</span><span class="nf">addSublayer</span><span class="p">(</span><span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">previewLayer</span><span class="p">)</span>
    <span class="k">self</span><span class="o">.</span><span class="n">view</span><span class="o">.</span><span class="nf">addSubview</span><span class="p">(</span><span class="n">previewView</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>

<p>Configure the capture session.</p>
<pre class="highlight swift"><code><span class="k">override</span> <span class="kd">func</span> <span class="nf">viewDidLoad</span><span class="p">()</span> <span class="p">{</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">delegate</span> <span class="o">=</span> <span class="k">self</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">deviceDelegate</span> <span class="o">=</span> <span class="k">self</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">videoDelegate</span> <span class="o">=</span> <span class="k">self</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">photoDelegate</span> <span class="o">=</span> <span class="k">self</span>

    <span class="c1">// modify .videoConfiguration, .audioConfiguration, .photoConfiguration properties</span>
    <span class="c1">// Compression, resolution, and maximum recording time options are available</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">videoConfiguration</span><span class="o">.</span><span class="n">maximumCaptureDuration</span> <span class="o">=</span> <span class="kt">CMTimeMakeWithSeconds</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">600</span><span class="p">)</span>
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">audioConfiguration</span><span class="o">.</span><span class="n">bitRate</span> <span class="o">=</span> <span class="mi">44000</span>
 <span class="p">}</span>
</code></pre>

<p>Start/stop the session when appropriate. These methods create a new <q>session</q> instance for &lsquo;NextLevel.shared.session&rsquo; when called.</p>
<pre class="highlight swift"><code><span class="k">override</span> <span class="kd">func</span> <span class="nf">viewWillAppear</span><span class="p">(</span><span class="n">_</span> <span class="nv">animated</span><span class="p">:</span> <span class="kt">Bool</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">viewWillAppear</span><span class="p">(</span><span class="n">animated</span><span class="p">)</span>     
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">start</span><span class="p">()</span>
    <span class="c1">// …</span>
<span class="p">}</span>
</code></pre>
<pre class="highlight swift"><code><span class="k">override</span> <span class="kd">func</span> <span class="nf">viewWillDisappear</span><span class="p">(</span><span class="n">_</span> <span class="nv">animated</span><span class="p">:</span> <span class="kt">Bool</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">viewWillDisappear</span><span class="p">(</span><span class="n">animated</span><span class="p">)</span>        
    <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">stop</span><span class="p">()</span>
    <span class="c1">// …</span>
<span class="p">}</span>
</code></pre>

<p>Video record/pause.</p>
<pre class="highlight swift"><code><span class="c1">// record</span>
<span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">record</span><span class="p">()</span>

<span class="c1">// pause</span>
<span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">pause</span><span class="p">()</span>
</code></pre>
<h3 id='editing-recorded-clips' class='heading'>Editing Recorded Clips</h3>

<p>Editing and finalizing the recorded session.</p>
<pre class="highlight swift"><code>
<span class="k">if</span> <span class="k">let</span> <span class="nv">session</span> <span class="o">=</span> <span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">session</span> <span class="p">{</span>

    <span class="c1">//..</span>

    <span class="c1">// undo</span>
    <span class="n">session</span><span class="o">.</span><span class="nf">removeLastClip</span><span class="p">()</span>

    <span class="c1">// various editing operations can be done using the NextLevelSession methods</span>

    <span class="c1">// export</span>
    <span class="n">session</span><span class="o">.</span><span class="nf">mergeClips</span><span class="p">(</span><span class="nv">usingPreset</span><span class="p">:</span> <span class="kt">AVAssetExportPresetHighestQuality</span><span class="p">,</span> <span class="nv">completionHandler</span><span class="p">:</span> <span class="p">{</span> <span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="kt">URL</span><span class="p">?,</span> <span class="nv">error</span><span class="p">:</span> <span class="kt">Error</span><span class="p">?)</span> <span class="k">in</span>
        <span class="k">if</span> <span class="k">let</span> <span class="nv">_</span> <span class="o">=</span> <span class="n">url</span> <span class="p">{</span>
            <span class="c1">//</span>
        <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="k">let</span> <span class="nv">_</span> <span class="o">=</span> <span class="n">error</span> <span class="p">{</span>
            <span class="c1">//</span>
        <span class="p">}</span>
     <span class="p">})</span>

    <span class="c1">//..</span>

<span class="p">}</span>
</code></pre>

<p>Videos can also be processed using the <a href="https://github.com/NextLevel/NextLevelSessionExporter">NextLevelSessionExporter</a>, a media transcoding library in Swift.</p>
<h2 id='custom-buffer-rendering' class='heading'>Custom Buffer Rendering</h2>

<p>‘NextLevel’ was designed for sample buffer analysis and custom modification in real-time along side a rich set of camera features.</p>

<p>Just to note, modifications performed on a buffer and provided back to NextLevel may potentially effect frame rate.</p>

<p>Enable custom rendering.</p>
<pre class="highlight swift"><code><span class="kt">NextLevel</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">isVideoCustomContextRenderingEnabled</span> <span class="o">=</span> <span class="kc">true</span>
</code></pre>

<p>Optional hook that allows reading <code>sampleBuffer</code> for analysis.</p>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">CameraViewController</span><span class="p">:</span> <span class="kt">NextLevelVideoDelegate</span> <span class="p">{</span>

    <span class="c1">// ...</span>

    <span class="c1">// video frame processing</span>
    <span class="kd">public</span> <span class="kd">func</span> <span class="nf">nextLevel</span><span class="p">(</span><span class="n">_</span> <span class="nv">nextLevel</span><span class="p">:</span> <span class="kt">NextLevel</span><span class="p">,</span> <span class="n">willProcessRawVideoSampleBuffer</span> <span class="nv">sampleBuffer</span><span class="p">:</span> <span class="kt">CMSampleBuffer</span><span class="p">)</span> <span class="p">{</span>
        <span class="c1">// Use the sampleBuffer parameter in your system for continual analysis</span>
    <span class="p">}</span>
</code></pre>

<p>Another optional hook for reading buffers for modification, <code>imageBuffer</code>. This is also the recommended place to provide the buffer back to NextLevel for recording.</p>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">CameraViewController</span><span class="p">:</span> <span class="kt">NextLevelVideoDelegate</span> <span class="p">{</span>

    <span class="c1">// ...</span>

    <span class="c1">// enabled by isCustomContextVideoRenderingEnabled</span>
    <span class="kd">public</span> <span class="kd">func</span> <span class="nf">nextLevel</span><span class="p">(</span><span class="n">_</span> <span class="nv">nextLevel</span><span class="p">:</span> <span class="kt">NextLevel</span><span class="p">,</span> <span class="n">renderToCustomContextWithImageBuffer</span> <span class="nv">imageBuffer</span><span class="p">:</span> <span class="kt">CVPixelBuffer</span><span class="p">,</span> <span class="n">onQueue</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">)</span> <span class="p">{</span>
            <span class="c1">// provide the frame back to NextLevel for recording</span>
        <span class="k">if</span> <span class="k">let</span> <span class="nv">frame</span> <span class="o">=</span> <span class="k">self</span><span class="o">.</span><span class="n">_availableFrameBuffer</span> <span class="p">{</span>
            <span class="n">nextLevel</span><span class="o">.</span><span class="n">videoCustomContextImageBuffer</span> <span class="o">=</span> <span class="n">frame</span>
        <span class="p">}</span>
    <span class="p">}</span>
</code></pre>

<p>NextLevel will check this property when writing buffers to a destination file. This works for both video and photos with <code>capturePhotoFromVideo</code>.</p>
<pre class="highlight swift"><code><span class="n">nextLevel</span><span class="o">.</span><span class="n">videoCustomContextImageBuffer</span> <span class="o">=</span> <span class="n">modifiedFrame</span>
</code></pre>
<h2 id='about' class='heading'>About</h2>

<p>NextLevel was initally a weekend project that has now grown into a open community of camera platform enthusists. The software provides foundational components for managing media recording, camera interface customization, gestural interaction customization, and image streaming on iOS. The same capabilities can also be found in apps such as <a href="http://snapchat.com">Snapchat</a>, <a href="http://instagram.com">Instagram</a>, and <a href="http://vine.co">Vine</a>.</p>

<p>The goal is to continue to provide a good foundation for quick integration (enabling projects to be taken to the next level) – allowing focus to placed on functionality that matters most whether it&rsquo;s realtime image processing, computer vision methods, augmented reality, or <a href="https://om.co/2018/07/23/even-leica-loves-computational-photography/">computational photography</a>.</p>
<h2 id='arkit' class='heading'>ARKit</h2>

<p>NextLevel provides components for capturing ARKit video and photo. This enables a variety of new camera features while leveraging the existing recording capabilities and media management of NextLevel.</p>

<p>If you are trying to capture frames from SceneKit for ARKit recording, check out the <a href="https://github.com/NextLevel/examples">examples</a> project.</p>
<h2 id='documentation' class='heading'>Documentation</h2>

<p>You can find <a href="https://nextlevel.github.io/NextLevel">the docs here</a>. Documentation is generated with <a href="https://github.com/realm/jazzy">jazzy</a> and hosted on <a href="https://pages.github.com">GitHub-Pages</a>.</p>
<h3 id='stickers' class='heading'>Stickers</h3>

<p>If you found this project to be helpful, check out the <a href="https://www.stickermule.com/en/user/1070732101/stickers">Next Level stickers</a>.</p>
<h3 id='project' class='heading'>Project</h3>

<p>NextLevel is a community – contributions and discussions are welcome!</p>

<ul>
<li>Feature idea? Open an <a href="https://github.com/nextlevel/NextLevel/issues">issue</a>.</li>
<li>Found a bug? Open an <a href="https://github.com/nextlevel/NextLevel/issues">issue</a>.</li>
<li>Need help? Use <a href="http://stackoverflow.com/questions/tagged/nextlevel">Stack Overflow</a> with the tag ’nextlevel’.</li>
<li>Questions? Use <a href="http://stackoverflow.com/questions/tagged/nextlevel">Stack Overflow</a> with the tag &lsquo;nextlevel&rsquo;.</li>
<li>Want to contribute? Submit a pull request.</li>
</ul>
<h3 id='related-projects' class='heading'>Related Projects</h3>

<ul>
<li><a href="https://github.com/piemonte/player">Player (Swift)</a>, video player in Swift</li>
<li><a href="https://github.com/piemonte/PBJVideoPlayer">PBJVideoPlayer (obj-c)</a>, video player in obj-c</li>
<li><a href="https://github.com/NextLevel/NextLevelSessionExporter">NextLevelSessionExporter</a>, media transcoding in Swift</li>
<li><a href="https://github.com/BradLarson/GPUImage3">GPUImage3</a>, image processing library</li>
<li><a href="https://github.com/rFlex/SCRecorder">SCRecorder</a>, obj-c capture library</li>
<li><a href="https://github.com/piemonte/PBJVision">PBJVision</a>, obj-c capture library</li>
</ul>
<h2 id='resources' class='heading'>Resources</h2>

<ul>
<li><a href="https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html">iOS Device Camera Summary</a></li>
<li><a href="https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html">AV Foundation Programming Guide</a></li>
<li><a href="https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVFoundationFramework/">AV Foundation Framework Reference</a></li>
<li><a href="https://developer.apple.com/documentation/arkit">ARKit Framework Reference</a></li>
<li><a href="https://github.com/apple/swift-evolution">Swift Evolution</a></li>
<li><a href="http://www.objc.io/issue-21/">objc.io Camera and Photos</a></li>
<li><a href="http://www.objc.io/issue-23/">objc.io Video</a></li>
<li><a href="https://www.objc.io/issues/23-video/core-image-video/">objc.io Core Image and Video</a></li>
<li><a href="http://ben-evans.com/benedictevans/2016/11/20/ku6omictaredoge4cao9cytspbz4jt">Cameras, ecommerce and machine learning</a></li>
<li><a href="http://om.co/2016/12/07/again-iphone-is-the-default-camera/">Again, iPhone is the default camera</a></li>
</ul>
<h2 id='license' class='heading'>License</h2>

<p>NextLevel is available under the MIT license, see the <a href="https://github.com/NextLevel/NextLevel/blob/master/LICENSE">LICENSE</a> file for more information.</p>

          </section>
        </section>
        <section id="footer">
          <p>&copy; 2019 <a class="link" href="http://nextlevel.engineering" target="_blank" rel="external">Patrick Piemonte</a>. All rights reserved. (Last updated: 2019-05-21)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
